/*
 * @Descripttion:
 * @Version: 1.0
 * @Author: undead
 * @Date: 2022-01-12 16:07:15
 * @LastEditors: undead
 * @LastEditTime: 2022-02-08 12:15:49
 */
const utils = require("../utils");

class ast {
  constructor(ast_parse) {
    if (!ast_parse) return;

    let jsPathArr = utils.readdirSync("./ast", "js");
    jsPathArr = jsPathArr.filter((x) => x.indexOf("/index.js") === -1);
    jsPathArr.forEach((js) => {
      const jsCore = require(js);
      if (!jsCore.name || !jsCore.checkFeature) return;
      try {
        console.log("执行脚本：" + jsCore.name);
        const checkResult = jsCore.checkFeature(ast_parse);
        console.log("匹配ast特性：" + checkResult);
        if (checkResult) {
          ast_parse = jsCore.init(ast_parse);
        }
        console.log("==========================================");
      } catch (e) {
        console.error("error:", e);
      }
    });
    return ast_parse;
  }
}
module.exports = ast;
